<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background: url(banner/april-13.jpg) repeat-x;
            background-size: 100px 100px;
            position: absolute;
        }
    </style>
</head>
<body>
    <button>开始</button><button>返回</button>
    <div class="box" style="left: 0px"></div>
    <script>
        let div =document.getElementsByTagName('div')[0]
        let button =document.getElementsByTagName("button")[0]
        let button1 =document.getElementsByTagName("button")[1]
        button.onclick=function()
        {
            const timer=setInterval(function(){
                  
            div.style.left=div.offsetLeft+100+'px'
            if(div.offsetLeft==500) {  //打印四次之后，就清除定时器
            clearInterval(timer);
        }
            },500)
        }
        button1.onclick=function()
        {
            const timer=setInterval(function(){
                  
            div.style.left=div.offsetLeft-100+'px'
            if(div.offsetLeft==0) {  //打印四次之后，就清除定时器
            clearInterval(timer);
        }
            },500)
        }
    </script>
</body>
</html>